package plugins;

import java.io.Serializable;
import java.util.ArrayList;
import plugins.GNotify.GnomeNotifyPlugin;

/**
 * Singleton with kind of multi-observer pattern
 * @author pieterc
 */
public class PluginManager implements NotifyPlugin, Serializable{

    private static PluginManager pm = new PluginManager();

    private ArrayList<NotifyPlugin> notifiers = new ArrayList<NotifyPlugin>();

    private PluginManager() {
        notifiers.add(new GnomeNotifyPlugin());
    }

    public static PluginManager getInstance(){
        return pm;
    }

    public void onNewMessages(int count) {
        for(NotifyPlugin notifier: notifiers){
            try{
                notifier.onNewMessages(count);
            }catch(Exception e){
                System.out.println("Error occured with notifierplugin: " + e.getMessage());
            }
        }
    }

    public void onNewMessage(String s) {
        for(NotifyPlugin notifier: notifiers){
            notifier.onNewMessage(s);
        }
    }





}
